package consumer;



import java.util.Enumeration;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.ServerSession;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.spring.ActiveMQConnectionFactory;


public class Con01 {
	
	public void Consumer()
	{

		try {
			ConnectionFactory cFactory = new ActiveMQConnectionFactory();
			Connection connection = cFactory.createConnection();
			Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
			connection.start();
			Queue queue =   session.createQueue("TestMQ");
			MessageProducer producer = session.createProducer(queue);
			Message message = session.createTextMessage("Who are you?");
			producer.send(message);
			
			MessageConsumer consumer = session.createConsumer(queue);
			consumer.setMessageListener( new MessageListener() {
				
				@Override
				public void onMessage(Message arg0) {
					// TODO Auto-generated method stub
					TextMessage textMessage =(TextMessage)arg0;
					try {
						System.out.println(textMessage.getText());
					} catch (JMSException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			});
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
		

}
